package cn.yuxiaoyuan.article.controller;

import cn.yuxiaoyuan.article.mongo.Comment;
import cn.yuxiaoyuan.article.service.CommentService;
import cn.yuxiaoyuan.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/article/{id}")
    public List<Comment> getArticleComment(@PathVariable("id")Long id){
        return commentService.findByArticleId(id);
    }

    @PostMapping
    public R add(@RequestBody Comment comment){
        comment.setCreateTime(new Date());
        comment.setState(1);
        commentService.save(comment);
        return R.ok();
    }
}
